<?php

class MySQL
{
    protected $server   = 'mysql:dbname=myvinyls;host=localhost; port=3306';
    protected $user     = 'myVinyls';
    protected $password = '268481';

    protected $pdo;

    public function __construct()
    {
        try {
            $pdo = new PDO($this->server, $this->user, $this->password);
            $this->pdo = $pdo;
        } catch(PDOException $e) {
            echo $e->getMessage();
            die();
        }
    }

    public function __desstruct()
    {
        $this->pdo = null;
    }

    public function insertVinyl ($artist,$title,$format,$pressing,$genre,$style,$releaseDate,$purchaseDate,$imageURL)
    {
        try {
            $query = "INSERT INTO `myvinyls`.`vinyls` (`artist`,`title`,`format`,`pressing`,`release date`,`genre`,`style`,`purchase date`,`image URL`)
                      VALUES ('".$artist."','".$title."','".$format."','".$pressing."','".$releaseDate."','".$genre."', '".$style."','".$purchaseDate."','".$imageURL."')";
            $this->pdo->exec($query);
        } catch(PDOException $e) {
            echo $e->getMessage();
            return false;
        }
    }

    public function selectVinyls()
    {
        $query = "SELECT * FROM vinyls";
        $data = $this->pdo->query($query);
        $result = $data->fetchAll();
        return $result;
    }
}